package com.jiujiu.model.DataBaseCommon;
import com.jiujiu.utitls.CreateMarker;
import com.jiujiu.utitls.MyFiles;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ZhaoJunZhou
 * @Date 2020/11/3
 */
public class ModelEntitys {
    /**
     * 一些简单的sql的参数
     */
    private SqlEntity sqlEntity;
    /**
     * 包含所有的列的属性包含(列名+类型)
     */
    private EntityModelBySql[] entityModelBySqls;
    private FilePath[] filePaths;
    public ModelEntitys(SqlEntity _sqlEntity, EntityModelBySql[] _entityModelBySqls) {
        sqlEntity = _sqlEntity;
        entityModelBySqls = _entityModelBySqls;
        filePaths = new FilePath[sqlEntity.getExtendList().size()];
        for (int i = 0; i < filePaths.length; i++) {
            filePaths[i] = FilePath.builder(sqlEntity.getExtendList().get(i));
        }
    }

    public void analysis(){
        for (int i = 0; i < filePaths.length; i++) {
            FilePath path = filePaths[i];
            Map<String, Object> data = new HashMap<>();
            data.put("entityModelBySqls", entityModelBySqls);
            data.put("common", sqlEntity);
            CreateMarker createMarker = new CreateMarker(path.getFrom(), path.getTo());
            createMarker.createFile(data);
        }
    }

    public SqlEntity getSqlEntity() {
        return sqlEntity;
    }

    public void setSqlEntity(SqlEntity sqlEntity) {
        this.sqlEntity = sqlEntity;
    }

    public EntityModelBySql[] getEntityModelBySqls() {
        return entityModelBySqls;
    }

    public void setEntityModelBySqls(EntityModelBySql[] entityModelBySqls) {
        this.entityModelBySqls = entityModelBySqls;
    }
}
class FilePath{
    private File from;
    private String to;

    public  static FilePath builder(Map<String,String> map) {
        String from = map.get("from");
        String to = map.get("to");
        return new FilePath(MyFiles.getFile(from), to);
    }

    public FilePath(File from, String to) {
        this.from = from;
        this.to = to;
    }

    public File getFrom() {
        return from;
    }

    public void setFrom(File from) {
        this.from = from;
    }

    public String getTo() {
        return to;
    }

    public void setTo(String to) {
        this.to = to;
    }
}